package co.baiku.boot.im.easemob.exception;

import java.util.HashMap;
import java.util.Map;

public enum EasemobErrorType {

    success(""), unauthorized("unauthorized"),
    auth_bad_access_token("auth_bad_access_token"),
    duplicate_unique_property_exists("duplicate_unique_property_exists"),
    service_resource_not_found("service_resource_not_found"),
    illegal_argument("illegal_argument"),
    json_parse("json_parse");
    String error;

    EasemobErrorType(String error) {
        this.error = error;
    }

    private static Map<String, EasemobErrorType> values = new HashMap<>();

    public static EasemobErrorType of(String error) {
        if (values.isEmpty()) {
            for (EasemobErrorType value : EasemobErrorType.values()) {
                values.put(value.getError(), value);
            }
        }
        if (values.containsKey(error)) {
            return values.get(error);
        }
        return success;
    }

    public String getError() {
        return error;
    }
}
